home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / URL Helper II / Source / URLHelperComponent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-14  |  4.7 KB  |  146 lines  |  [TEXT/MMCC]

  1. /***
  2.  * URLHelperComponent.c
  3.  *
  4.  *  This is the URLHelper dispatch routine...
  5.  *
  6.  ***/
  7.  
  8. #include "debug_me.h"
  9.  
  10. #include "URLHelperComponent.h"
  11. #include "URLHelperComponentPrivate.h"
  12.  
  13. /**
  14.  * URLHelperDispatcher
  15.  *
  16.  *  This routine is called as the entrace to the component.  We dispatch to the other fellows
  17.  *
  18.  **/
  19.  
  20. #ifdef DEBUG_IT
  21. pascal ComponentResult URLHelperDispatcher (ComponentParameters    *params, Handle storage)
  22. #else
  23. pascal ComponentResult main (ComponentParameters *params, Handle storage)
  24. #endif
  25.  
  26. {
  27.     ComponentFunctionUPP    theJob = 0;
  28.     ComponentResult            theCErr;
  29.  
  30.     /**
  31.      ** If the what code is less than zero, then we have a component manager
  32.      ** request.  We have to create the UPP for each routine.  Deallocate it at the end
  33.      ** when we are done with it.
  34.      **/
  35.     
  36.     if (params -> what < 0) {
  37.         switch (params -> what) {
  38.             case kComponentOpenSelect:            // Open this component
  39.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperOpen,
  40.                             uupURLHelperOpen, GetCurrentISA());
  41.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  42.                 break;
  43.  
  44.             case kComponentCloseSelect:            // Close this component
  45.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperClose,
  46.                             uupURLHelperClose, GetCurrentISA());
  47.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  48.                 break;
  49.  
  50.             case kComponentCanDoSelect:            // Can we do this function?
  51.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperCanDo,
  52.                             uupCanDo, GetCurrentISA());
  53.                 theCErr = CallComponentFunction (params, theJob);
  54.                 break;
  55.  
  56.             case kComponentVersionSelect:            // What version is this component ?
  57.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperVersion,
  58.                             uupVersion, GetCurrentISA());
  59.                 theCErr = CallComponentFunction (params, theJob);
  60.                 break;
  61.  
  62.             case kComponentTargetSelect:            // We are being captured by another component
  63.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperTarget,
  64.                             uupURLHelperTarget, GetCurrentISA());
  65.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  66.                 break;
  67.  
  68.             default:                                // A request code we don't deal with
  69.                 theCErr = paramErr;
  70.                 break;
  71.  
  72.         }
  73.         
  74.     } else {
  75.  
  76.     /**
  77.      ** One of our request codes needs to be processed!!! Yeah!
  78.      **/
  79.  
  80.         switch (params -> what) {
  81.  
  82.             case kDoGetMirrorList:                // Return ref to a installed mirror list
  83.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperGetMirrorList,
  84.                             uupURLHelperGetMirrorList, GetCurrentISA());
  85.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  86.                 break;
  87.  
  88.             case kDoNewMirrorList:                // Return ref to new installed mirror list
  89.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperNewMirrorList,
  90.                             uupURLHelperNewMirrorList, GetCurrentISA());
  91.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  92.                 break;
  93.  
  94.             case kDoAddMirror:                    // Add a new mirror to the list
  95.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperAddMirror,
  96.                             uupURLHelperAddMirror, GetCurrentISA());
  97.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  98.                 break;
  99.  
  100.             case kDoNumberOfMirrors:            // How many useful mirrors
  101.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperNumberOfMirrors,
  102.                             uupURLHelperNumberOfMirrors, GetCurrentISA());
  103.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  104.                 break;
  105.  
  106.             case kDoGetUsableMirror:            // Return a mirror we can use for subst.
  107.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperGetUsableMirror,
  108.                             uupURLHelperGetUsableMirror, GetCurrentISA());
  109.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  110.                 break;
  111.  
  112.             case kDoNewParseState:                // Make up a new parse state here!
  113.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperNewParseState,
  114.                             uupURLHelperNewParseState, GetCurrentISA());
  115.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  116.                 break;
  117.  
  118.             case kDoDisposeParseState:            // Dispose of a parse state here!
  119.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperDisposeParseState,
  120.                             uupURLHelperDisposeParseState, GetCurrentISA());
  121.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  122.                 break;
  123.  
  124.             case kDoGetMirrorRep:                // Replace one mirror with another!
  125.                 theJob = (ComponentFunctionUPP) NewRoutineDescriptor (_URLHelperGetMirrorRep,
  126.                             uupURLHelperGetMirrorRep, GetCurrentISA());
  127.                 theCErr = CallComponentFunctionWithStorage (storage, params, theJob);
  128.                 break;
  129.  
  130.             default:
  131.                 theCErr = paramErr;
  132.                 break;
  133.         }
  134.     }
  135.  
  136.     /**
  137.      ** Done.  Return the result and dispose of the UPP if we used it
  138.      **/
  139.     
  140.     if (theJob){
  141.         DisposeRoutineDescriptor (theJob);
  142.     }
  143.  
  144.     return    theCErr;
  145. }
  146.